package PlaneGame.CODE;

import javax.sound.sampled.*;
import java.io.File;

public class GameBGM {
    AudioInputStream audioInputStream;
    AudioFormat format;
    DataLine.Info info;
    Clip clip;
    String path;
    GameBGM( String path){
        this.path=path;
    }
    void fang() {
        try {
            audioInputStream = AudioSystem.getAudioInputStream(new File(path));
            format = audioInputStream.getFormat();
            info = new DataLine.Info(Clip.class, format);
            clip = (Clip) AudioSystem.getLine(info);
            clip.open(audioInputStream);
            clip.start();
            Thread.sleep(1000);
            clip.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    void ting(){
        clip.stop();
    }
}